/**
 * Created by IntelliJ IDEA
 *
 * @author zhengjie
 * @Date:2022/1/12 15:23
 * @Version 1.0
 */
package com.zj.ssm.util;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;
import lombok.Data;
import org.springframework.web.multipart.MultipartFile;

import java.io.InputStream;
import java.util.UUID;

@Data
public class OSSUtil {

    private String endpoint ;
    private String accessKeyId;
    private String accessKeySecret;
    private String bucketName;
    private String path;


    public String uploadOSS(MultipartFile headImg){
       try {
           String fileName= UUID.randomUUID().toString()+headImg.getContentType().replace("image/",".");
           OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);
           InputStream inputStream = headImg.getInputStream();
           ossClient.putObject(bucketName , fileName, inputStream);
           ossClient.shutdown();
            return path+fileName;
       }catch (Exception e){
           e.printStackTrace();
       }
       return null;
    }

}
